package com.yyyit.bg2.controller;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.Select;

import com.yyyit.bg2.tools.tools;

public class User {
	public static String addUser(WebDriver driver, String baseUrl) {
		try {

			driver.get(baseUrl + "user/puser.jsp#/account/member");
			String tmp = "test" + tools.time8();
			driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
			driver.findElement(By.linkText("添加")).click();
			driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
			driver.findElement(By.name("name")).sendKeys(tmp);
			driver.findElement(By.name("nick")).sendKeys(tmp);
			Select s = new Select(driver.findElement(By
					.xpath("//div/div/select")));
			s.selectByVisibleText("地区管理员");
			driver.findElement(By.name("mobile")).sendKeys("15001300532");
			// driver.findElement(By.linkText("确定")).click();
			driver.findElement(By.xpath("//button[@ng-click='confirm()']"))
					.click();
			return tmp;
		} catch (Exception e) {
			// TODO: handle exception
		} finally {

		}
		return "添加用户失败";
	}

	public static String searchAndDeleteUser(WebDriver driver, String baseUrl,
			String au) {
		try {
			driver.get(baseUrl + "user/puser.jsp#/account/member");
			tools.placeholder(driver, "请输入账号").sendKeys(au);
			driver.findElement(By.xpath("//button[@type='submit']")).click();
			driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
			driver.findElement(By.linkText("删除")).click();
			driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
			driver.findElement(By.xpath("//button[@type='submit']")).click();
			driver.findElement(By.xpath("//button[@ng-disabled='item.deleting']")).click();
			return "搜索并删除用户成功";
		} catch (Exception e) {
			// TODO: handle exception
		} finally {

		}
		return "搜索并删除用户失败";

	}
}
